<template>
<div>
  <div class="search-box">
    <div class="search-box-left">
      <el-input class="search-box-left-input" @keyup.enter.native="getList" v-model="startUserName" placeholder="请输入内容"></el-input>
    </div>
    <div class="search-box-right">
      审批类型：
      <el-select v-model="approvalType" placeholder="请选择审批类型" @change="selectApproval">
        <el-option
          v-for="item in approvalOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </div>
  </div>
  <div class="wrap" v-loading="loading">
    <el-tabs :tab-position="tabPosition" style="height: 400px;"  v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="我审批的">
        <div class="overflow" v-if="historyTaskData.length > 0">
          <div class="wrap-items" v-for="(item,index) in historyTaskData" :key="index">
            <div class="wrap-items-left">
                <div class="wrap-items-left-check">
                  <el-checkbox v-model="item.isChecked"></el-checkbox>
                </div>
            </div>
           <!-- 备用金申请 -->
            <div class="wrap-items-middle" v-if="item.schemeName=='备用金申请'">
              <div class="wrap-items-middle-title">
                <div class="first-name">
                  <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                  <img v-else src="../../../assets/card/morenh.png">
                </div>
                <div class="wrap-items-middle-title-content">{{item.startUser}}提交的{{item.schemeName}}</div>
              </div>

              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">申请人:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.apply_name">{{item.data.apply_name}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">申请金额:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.apply_amount">{{item.data.apply_amount}}元</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">收款账号:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.collection_account">{{item.data.collection_account}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">使用日期：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.use_date">{{item.data.use_date}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">归还日期：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.return_date">{{item.data.return_date}}</div>
              </div>
            </div>
            <!-- 出差 -->
            <div class="wrap-items-middle" v-else-if="item.schemeName=='出差'">
              <div class="wrap-items-middle-title">
                <div class="first-name">
                  <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                  <img v-else src="../../../assets/card/morenh.png">
                </div>
                <div class="wrap-items-middle-title-content">{{item.startUser}}提交的{{item.schemeName}}</div>
              </div>

              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">交通工具:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Vehicle">{{item.data.F_Vehicle}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">单程/往返:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Onewayroundtrip">{{item.data.F_Onewayroundtrip}}元</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">出发城市:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_GoCityName">{{item.data.F_GoCityName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">目的城市：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_FromCityName">{{item.data.F_FromCityName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">备注：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Remarks">{{item.data.F_Remarks}}</div>
              </div>
            </div>
            <div class="wrap-items-right">
                <div class="wrap-items-left-adopt">
                  <div class="refuse" v-if="item.status == 0">审批拒绝</div>
                  <div class="adopt" v-else-if="item.status == 1">审批通过</div>
                  <div class="processing" v-else>审批中</div>
                </div>
            </div>
          </div>
        </div>
        <div class="approval-no-data" v-else>
          <img src="../../../assets/flowlist/no-data.png">
        </div>
      </el-tab-pane>
      <el-tab-pane label="我发起的">
        <div class="overflow" v-if="myTaskData.length > 0">
          <div class="wrap-items" v-for="(item,index) in myTaskData" :key="index">
            <div class="wrap-items-left">
                <div class="wrap-items-left-check">
                  <el-checkbox v-model="item.isChecked"></el-checkbox>
                </div>
            </div>
            <!-- 备用金申请 -->
            <div class="wrap-items-middle" v-if="item.schemeName=='备用金申请'">
              <div class="wrap-items-middle-title">
                <div class="first-name">
                  <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                  <img v-else src="../../../assets/card/morenh.png">
                </div>
                <div class="wrap-items-middle-title-content">{{item.startUser}}提交的{{item.schemeName}}</div>
              </div>

              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">申请人:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.apply_name">{{item.data.apply_name}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">申请金额:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.apply_amount">{{item.data.apply_amount}}元</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">收款账号:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.collection_account">{{item.data.collection_account}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">使用日期：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.use_date">{{item.data.use_date}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">归还日期：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.return_date">{{item.data.return_date}}</div>
              </div>
            </div>
            <!-- 出差 -->
            <div class="wrap-items-middle" v-else-if="item.schemeName=='出差'">
              <div class="wrap-items-middle-title">
                <div class="first-name">
                  <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                  <img v-else src="../../../assets/card/morenh.png">
                </div>
                <div class="wrap-items-middle-title-content">{{item.startUser}}提交的{{item.schemeName}}</div>
              </div>

              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">交通工具:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Vehicle">{{item.data.F_Vehicle}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">单程/往返:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Onewayroundtrip">{{item.data.F_Onewayroundtrip}}元</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">出发城市:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_GoCityName">{{item.data.F_GoCityName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">目的城市：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_FromCityName">{{item.data.F_FromCityName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">备注：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Remarks">{{item.data.F_Remarks}}</div>
              </div>
            </div>
            <div class="wrap-items-right">
                <div class="wrap-items-left-adopt">
                  <div class="refuse" v-if="item.status==0">审批拒绝</div>
                  <div class="adopt" v-else-if="item.status==1">审批通过</div>
                  <div class="processing" v-else>审批中</div>
                </div>
            </div>
          </div>
        </div>
        <div class="approval-no-data" v-else>
          <img src="../../../assets/flowlist/no-data.png">
        </div>
      </el-tab-pane>
      <el-tab-pane label="我收到的">
        <div class="overflow" v-if="manualTaskData.length > 0">
          <div class="wrap-items" v-for="(item,index) in manualTaskData" :key="index">
            <div class="wrap-items-left">
                <div class="wrap-items-left-check">
                  <el-checkbox v-model="item.isChecked"></el-checkbox>
                </div>
            </div>
            <!-- 备用金申请 -->
            <div class="wrap-items-middle" v-if="item.schemeName=='备用金申请'">
              <div class="wrap-items-middle-title">
                <div class="first-name">
                  <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                  <img v-else src="../../../assets/card/morenh.png">
                </div>
                <div class="wrap-items-middle-title-content">{{item.startUser}}提交的{{item.schemeName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">申请人:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.apply_name">{{item.data.apply_name}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">申请金额:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.apply_amount">{{item.data.apply_amount}}元</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">收款账号:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.collection_account">{{item.data.collection_account}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">使用日期：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.use_date">{{item.data.use_date}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">归还日期：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.return_date">{{item.data.return_date}}</div>
              </div>
            </div>
            <!-- 出差 -->
            <div class="wrap-items-middle" v-else-if="item.schemeName=='出差'">
              <div class="wrap-items-middle-title">
                <div class="first-name">
                  <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                  <img v-else src="../../../assets/card/morenh.png">
                </div>
                <div class="wrap-items-middle-title-content">{{item.startUser}}提交的{{item.schemeName}}</div>
              </div>

              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">交通工具:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Vehicle">{{item.data.F_Vehicle}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">单程/往返:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Onewayroundtrip">{{item.data.F_Onewayroundtrip}}元</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">出发城市:</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_GoCityName">{{item.data.F_GoCityName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">目的城市：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_FromCityName">{{item.data.F_FromCityName}}</div>
              </div>
              <div class="wrap-items-middle-type">
                <div class="wrap-items-middle-type-left">备注：</div>
                <div class="wrap-items-middle-type-right" v-if="item.data && item.data.F_Remarks">{{item.data.F_Remarks}}</div>
              </div>
            </div>
            <div class="wrap-items-right">
                <div class="wrap-items-left-adopt">
                  <div class="refuse" v-if="item.status==0">审批拒绝</div>
                  <div class="adopt" v-else-if="item.status==1">审批通过</div>
                  <div class="processing" v-else>审批中</div>
                </div>
            </div>
          </div>
        </div>
        <div class="approval-no-data" v-else>
          <img src="../../../assets/flowlist/no-data.png">
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
  <div class="el-paganation">
    <el-pagination
      class="el-paganation-i"
      background
      @current-change="handleCurrentChange"
      layout="total,prev, pager, next"
      :total="total">
    </el-pagination>
  </div>
</div>
</template>
<script>
import {getMyTask,getHistoryTask,getManualTask} from "@/api/workFlow/WFProcess";//我的流程
export default {
  props:{},
  data(){
    return{
      tabPosition: 'left',
      approvalOptions: [
        {
          value: '备用金申请',
          label: '备用金申请'
        }
      ],
      activeName:0,
      total:0,
      //查询条件
      limit:1,//当前页数
      size:5,//每页大小
      approvalType:'备用金申请',//审批类型
      startUserName:'',
      //我审批的：已办
      historyTaskData:[],
      historyTaskTotal:0,
      //我发起的：我的流程
      myTaskData:[],
      myTaskTotal:0,
      //我收到的：传阅
      manualTaskData:[],
      manualTaskTotal:0,
      loading:false
    }
  },
  async mounted(){
    //我审批的：已办
    await this.getHistoryTask()
    //我发起的：我的流程
    await this.getMyTask()
    // 我收到的：传阅
    await this.getManualTask()
  },
  methods:{
    init(){
      if(this.activeName == 0){
        this.getHistoryTask()
      }else if(this.activeName == 1){
        this.getMyTask()
      }else{
        this.getManualTask()
      }
    },
    getHistoryTask(){
      let params = {
        limit: this.limit,
        size: this.size,
        order: 'desc',
        approvalType:this.approvalType,//审批类型
        startUserName:this.startUserName,//发起人
      }
      this.loading = true
      getHistoryTask(params).then(res => {
          if(res.data.success){
            this.loading = false
            this.historyTaskData = res.data.data.Rows
            this.historyTaskTotal  = res.data.data.Total
            this.total = this.historyTaskTotal
          }
        })
    },
    getMyTask(){
      let params = {
        limit: this.limit,
        size: this.size,
        order: 'desc',
        approvalType:this.approvalType,//审批类型
        startUserName:this.startUserName,//发起人
      }
      this.loading = true
      getMyTask(params).then(res => {
          if(res.data.success){
            console.log(res);
            this.loading = false
            this.myTaskData = res.data.data.Rows
            this.myTaskTotal  = res.data.data.Total
            // this.total = this.myTaskTotal
          }
        })
    },
    getManualTask(){
      let params = {
        limit: this.limit,
        size: this.size,
        order: 'desc',
        approvalType:this.approvalType,//审批类型
        startUserName:this.startUserName,//发起人
      }
      this.loading = true
      getManualTask(params).then(res => {
          if(res.data.success){
            this.loading = false
            this.manualTaskData = res.data.data.Rows
            this.manualTaskTotal  = res.data.data.Total
            // this.total = this.manualTaskTotal
          }
      })
    },
    selectApproval(){
      if(this.activeName == 0){
        this.getHistoryTask()
      }else if(this.activeName == 1){
        this.getMyTask()
      }else if(this.activeName == 2){
        this.getManualTask()
      }
    },
    getList(){
      if(this.activeName == 0){
        this.getHistoryTask()
      }else if(this.activeName == 1){
        this.getMyTask()
      }else if(this.activeName == 2){
        this.getManualTask()
      }
    },
    handleClick(){
      if(this.activeName == 0){
        this.getHistoryTask()
       this.total = this.historyTaskTotal
      }else if(this.activeName == 1){
        this.getMyTask()
        this.total = this.myTaskTotal
      }else if(this.activeName == 2){
        this.getManualTask()
        this.total = this.manualTaskTotal
      }
    },
    handleCurrentChange(currentPage){
      this.limit = currentPage
      //判断选项卡，然后决定调用哪个接口
      if(this.activeName == 0){
        this.getHistoryTask()
      }else if(this.activeName == 1){
        this.getMyTask()
      }
      
    },
  }
}
</script>
<style scoped>
  /* 关联审批单开始 */
  ::v-deep .el-dialog__footer{
    border-top: 1px solid #eee;
  }
  .height16{
    height: 16px;
  }
  .wrap{
    height: 400px;
    border: 1px solid #eee;
    display: flex;
    flex-direction: row;
  }
  .wrap-items{
    width: 720px;
    border-bottom: 1px solid #eee;
    display: flex;
    flex-direction: row;
  }
  .wrap-items-left{
    height: 100%;
    width: 10%;
  }
  .wrap-items-left-check{
    width: 100%;
    height: 40px;
    margin-top: 16px;
    text-align: center;
  }
  .adopt{
    width: 71px;
    height: 30px;
    background: #D8F8DD;
    border-radius: 3px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #10A300;
    line-height: 30px;
    text-align: center;
    margin: 0 auto;
  }
  .refuse{
    width: 71px;
    height: 30px;
    background: #FFEBEB;
    border-radius: 3px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #FD513B;
    line-height: 30px;
    text-align: center;
    margin: 0 auto;
  }
  .processing{
    width: 71px;
    height: 30px;
    background: #FFF2E0;
    border-radius: 3px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #FE8B04;
    line-height: 30px;
    text-align: center;
    margin: 0 auto;
  }
  .wrap-items-middle{
    height: 100%;
    width: 65%;
  }
  .wrap-items-right{
    height: 100%;
    width: 15%;
  }
  .wrap-items-left-adopt{
    margin-top: 16px;
  }
  .wrap-items-middle-title{
    margin-top: 16px;
    display: flex;
    flex-direction: row;
  }
  .first-name{
    width: 40px;
    height: 40px;
    border-radius: 4px;
  }
  .first-name> img{
    width: 100%;
    height: 100%;
  }
  .wrap-items-middle-title-content{
    font-size: 16px;
    font-family: PingFang-SC-Bold, PingFang-SC;
    font-weight: 400;
    color: #333333;
    line-height: 40px;
    margin-left: 16px;
  }
  .wrap-items-middle-type{
    display: flex;
    flex-direction: row;
  }
  .wrap-items-middle-type-left{
    width: 20%;
    height: 100%;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .wrap-items-middle-type-right{
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #555555;
  }
  .overflow{
    height: 400px;
    overflow: scroll;
  }
  .del_items{
    width: 350px;
    height: 32px;
    margin-top: 4px;
    background: rgb(246, 246, 246);
    border-radius: 4px;
    display: flex;
    flex-direction: row;

  }
  .del-items-left{
    width: 32px;
    height: 32px;
    text-align: center;
  }
  .del-items-left > img{
    width: 22px;
    height: 22px;
    margin-top: 5px;
  }
  .del-items-middle{
    width: 180px;
    height: 32px;
    font-size: 16px;
    font-weight: 400;
    text-align: left;
    line-height: 32px;
  }
  .del-items-processing{
     width: 80px;
    font-size: 16px;
    font-weight: 400;
    text-align: center;
    line-height: 32px;
    color: #FE8B04;
  }
  .del-items-refuse{
     width: 80px;
    font-size: 16px;
    font-weight: 400;
    text-align: center;
    line-height: 32px;
    color: #FD513B;
  }
  .del-items-adopt{
     width: 80px;
    font-size: 16px;
    font-weight: 400;
    text-align: center;
    line-height: 32px;
    color: #10A300;
  }
  .del-items-right{
    width: 90px;
    height: 32px;
  }
  .del-items-close{
    width: 32px;
    height: 32px;
    margin-left: 24px;
  }
  .search-box{
    width: 100%;
    height: 32px;
    margin: 8px 0;
    display: flex;
    flex-direction: row;
  }
  .search-box-left{
    width: 50%;
    height: 32px;
    text-align: center;
  }
  .search-box-left-input{
    width: 300px;
  }
  .search-box-right{
    width: 50%;
    height: 32px;
    text-align: center;
  }
  .el-paganation{
    width: 100%;
    height: 40px;
    text-align: center;
  }
  .el-paganation-i{
    margin-top: 16px;
  }
  
  .approval-no-data{
    width: 720px;
    height: 400px;
    text-align: center;
  }
  .approval-no-data::after{
    content: "";
    display: inline-block;
    height: 100%;
    width: 1px;
    vertical-align: middle;
  }
  .approval-no-data>img{
    vertical-align: middle;
  }
</style>